<script setup lang="ts">
import {
    EAnimateCSSUtil,
    EButton,
    EClipboardUtil,
    EMessage,
} from 'exploria-ui';
import { ref, useTemplateRef } from 'vue';

import uiPackageJson from 'exploria-ui/package.json';
import SiteName from '@/views/HomeView/parts/Index/SiteName.vue';
import Header from '@/components/Header/Header.vue';
import WaveNoise from '@/components/WaveNoise/WaveNoise.vue';

const cmd = 'pnpm add ' + uiPackageJson.name;
const showMark = ref(false);

const homeViewRef = useTemplateRef<HTMLDivElement>('home-view');

const scrollToLlbPage = () => {
    homeViewRef
        .value!.querySelector('.lib-page')!
        .scrollIntoView({ behavior: 'smooth' });
};

const mouseenter = (e: MouseEvent) => {
    const title = e.currentTarget as HTMLElement;
    EAnimateCSSUtil.once(title, 'animate__tada');
};
</script>

<template>
    <!-- 用户看到的第一个页面 -->
    <div class="index">
        <WaveNoise class="bg" />
        <Header />
        <div class="index-main">
            <SiteName @mouseenter="(e: MouseEvent) => mouseenter(e)" />
            <span class="version"> v{{ uiPackageJson.version }} </span>
            <div class="description">
                基于 Vue@
                {{ uiPackageJson.devDependencies['vue'] }} 的 UI 框架
            </div>
            <div class="cmd">
                {{ cmd }}
                <img
                    class="icon-img"
                    src="../../../../assets/copy.svg"
                    alt=""
                    @click="
                        () =>
                            EClipboardUtil.copy(cmd).then(() =>
                                EMessage.success('复制成功: ' + cmd),
                            )
                    "
                />
            </div>
            <div class="core-info">
                <div class="item">Vite</div>
                <div class="item">TypeScript</div>
                <div class="item">Scss</div>
            </div>
            <div class="btn-box">
                <EButton @click="showMark = true">快速上手</EButton>
                <EButton @click="scrollToLlbPage">安装</EButton>
            </div>
        </div>
    </div>
</template>

<style lang="scss" scoped>
@use '@/style/global' as global;
@use 'sass:list';

.index {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    user-select: none;
    position: relative;

    .bg {
        position: absolute;
        inset: 0;
        z-index: -1;
    }

    .header {
        height: global.$header-height;
    }

    .index-main {
        flex: 1;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        gap: 20px;

        .title {
            font-size: 50px;
            font-weight: bold;
            position: relative;

            @include global.useTheme(
                phone,
                (
                    font-size: 30px,
                )
            );

            .version {
                position: absolute;
                left: 100%;
                background-color: rgba(255, 255, 255, 0.5);
                border-radius: 3px;
                padding: 2px 5px;
                font-size: 14px;
                font-weight: bold;
                box-shadow: global.$box-shadow;
            }
        }

        .cmd {
            background-color: #ffffff55;
            border-radius: 5px;
            border: solid 1px #ffffff55;
            display: flex;
            align-items: center;
            gap: 2px;
            padding: 5px 10px;

            .icon-img {
                cursor: pointer;
                width: 20px;
                height: 20px;
                margin-left: 10px;
            }
        }

        .core-info {
            display: flex;
            align-items: center;
            gap: 10px;
            margin: 20px 0;

            .item {
                padding: 10px 15px;
                border-radius: 5px;
                color: white;

                // 颜色列表
                $colors: #d26565, #6cdfe8, #63ca63;

                // 为 .item 的前 N 个（N = length($colors)）子元素循环赋值
                @for $i from 1 through list.length($colors) {
                    &:nth-child(#{$i}) {
                        background-color: list.nth(
                            $colors,
                            $i
                        ); // 用 nth() 取列表中的第 $i 项
                    }
                }
            }
        }

        .btn-box {
            display: flex;
            gap: 20px;
        }
    }
}
</style>
